package com.sui.bigdata.rtcadmin.repository.mapper;

import com.sui.bigdata.rtcadmin.dto.MetaDto;
import com.sui.bigdata.rtcadmin.repository.model.Meta;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author YongChen
 * @date 2019/11/5 14:19
 * @description
 * @email yong_chen@sui.com
 */
@Mapper
@Component
public interface MetaMapper {
    @Insert("insert into flink_sql_meta(table_name,field_info,prop,component,database_name,create_table_statement) " +
            "values(#{tableName},#{fieldInfo},#{prop},#{component},#{databaseName},#{createTableStatement}) " +
            "ON DUPLICATE KEY UPDATE " +
            "field_info=#{fieldInfo},prop=#{prop},component=#{component},create_table_statement=#{createTableStatement}")
    @Options(useGeneratedKeys = true)
    void insert(Meta meta) throws Exception;

    @Delete("delete from flink_sql_meta where table_name= #{tableName} and database_name = #{databaseName}")
    void delete(@Param("tableName")String tableName, @Param("databaseName")String databaseName) throws Exception;

    @Select("select * from flink_sql_meta ")
    @ResultType(Meta.class)
    List<Meta> queryAll();

    @Select("select * from flink_sql_meta where table_name= #{tableName}")
    @ResultType(Meta.class)
    Meta queryByTableName(@Param("tableName")String tableName);

    @Select("select * from flink_sql_meta where table_name= #{tableName} and database_name = #{databaseName}")
    @ResultType(Meta.class)
    Meta queryByTableNameAndDB(@Param("tableName")String tableName, @Param("databaseName")String databaseName);

    @Select("select * from flink_sql_meta where type = #{type} and component = #{component}")
    @ResultType(Meta.class)
    List<Meta> queryByType(@Param("type")String type,@Param("component")String component);




}
